import { ref } from 'vue'
import { defineStore } from 'pinia'

export const usersStore = defineStore(
  'users',
  () => {
    const users = ref({
      username: '',
      password: '',
      enabled: 1,
      realName: '',
      avatar: '',
      joinDate: '',
      usersTypeId: 0,
      rememberMe: false
    })

    function setUsers(u: any) {
      users.value.username = u.username
      users.value.password = u.password
      users.value.enabled = u.enabled
      users.value.realName = u.realName
      users.value.avatar = u.avatar
      users.value.joinDate = u.joinDate
      users.value.usersTypeId = u.usersTypeId
      users.value.rememberMe = u.rememberMe
    }

    function setRememberMe(rememberMe: boolean) {
      users.value.rememberMe = rememberMe
    }

    function setPassword(password: string) {
      users.value.password = password
    }

    function setRealName(realName: string) {
      users.value.realName = realName
    }

    function setAvatar(avatar: string) {
      users.value.avatar = avatar
    }
    return { users, setUsers, setRememberMe, setPassword, setRealName, setAvatar }
  },
  {
    persist: true
  }
)
